<template>
	<view class="container">
		<view class="title">用户登录</view>
		<view class="tip">请使用WanAndroid账号登录！！</view>

		<view class="user-account">
			<view class="lable">用户名</view>
			<input v-model="userName" class="user-input input" placeholder="输入用户名"  />
		</view>
		<view class="user-pwd">
			<view class="lable">密码</view>
			<input v-model="pwd" class="pwd-input input" placeholder="输入密码" type="safe-password" />
		</view>
		<view class="login-btn" @click="doLogin">登录</view>
		<view @click="toRegister">
			没有账号？去注册
		</view>
	</view>
</template>

<script>
	import {
		loginUrl
	} from '../../api/constant.js'
	import {
		httpPost
	} from '../../api/httpUtils.js'
	export default {
		data() {
			return {
				userName: '',
				pwd: ''
			}
		},
		methods: {
			toRegister() {
              uni.navigateTo({
              	url:'/pages/register/register'
              })
			},
			async doLogin() {
				
				var data = {
					username: this.userName,
					password: this.pwd
				}
				let res = await httpPost(loginUrl, data)
				let {errorCode,errorMsg=''}=res
				
				if (errorCode==0) {
					uni.showToast({
						title: "登录成功"
					})
					uni.navigateBack()
				}
				else{
					uni.showToast({
						title:errorMsg
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		padding: 32rpx;

		.login-btn {
			text-align: center;
			font-size: 32rpx;
			height: 60rpx;
			color: white;
			background-color: blue;
			margin-bottom: 16rpx;
			border-radius: 10rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}

		.title {
			font-size: 32rpx;
			font-weight: 500;
			margin-bottom: 32rpx;
		}

		.user-account,
		.user-pwd {
			display: flex;
			margin: 32rpx 0rpx;

			.lable {
				width: 100rpx;
			}

			/deep/ .input {


				display: flex;
				padding-left: 10rpx;

			}

		}

		.user-account {
			.user-input {
				flex: 1;
				margin-left: 16rpx;
				border: 1px solid green;
				border-radius: 6rpx;
			}
		}

		.user-pwd {
			.pwd-input {
				flex: 1;
				margin-left: 16rpx;
				border: 1px solid green;
				border-radius: 6rpx;
			}
		}
	}
</style>
